package net.optix.ip.business
{
	import com.adobe.cairngorm.business.Responder;
	
	import mx.rpc.http.HTTPService;
	
	import net.optix.ip.model.ModelLocator;
	import net.optix.ip.vo.AssignVO;
	import net.optix.ip.vo.BidVO;
	import net.optix.ip.vo.RequestBidVO;
	
	public class BudgetDelegate
	{
		private var responder:Responder;
		private var service:HTTPService;
		
		public function	listener():void
		{
			service.method = "POST";
            service.resultFormat	=	HTTPService.RESULT_FORMAT_E4X;
            service.addEventListener("result", responder.onResult);
            service.addEventListener("fault", responder.onFault);
		}
		
		public function getBudgets(responder:Responder,id:int,type:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Budget/GetBudgets";
            this.listener();
            service.send({
            	ID:id,
            	Type:type});
		}
		
		public function returnCase(responder:Responder,id:int,type:int):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Budget/ReturnCase";
            this.listener();
            service.send({
            	ID:id,
            	Type:type});
		}
		
		public function requestBid(responder:Responder,vo:RequestBidVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Budget/RequestBid";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	ID:vo.id,
            	Type:vo.category,
				BBid:vo.bBid,
				MaxBudget:vo.maxBudget,
				FillingDate:vo.fillingDate});
		}
		
		public function setBudget(responder:Responder,vo:BidVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Budget/SetBudget";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	FirmID:vo.firmID,
            	ID:vo.id,
            	Budget:vo.budget,
            	Type:vo.type
            	});
		}
		
		public function assignToFirm(responder:Responder,vo:AssignVO):void
		{
			this.responder	=	responder;
			service 		= 	new HTTPService();
			service.url		=	ModelLocator.getInstance().url+"/Budget/AssignToFirm";
            this.listener();
            //service.resultFormat	=	HTTPService.RESULT_FORMAT_TEXT;
            service.send({
            	ID:vo.id,
            	FirmID:vo.firmID,
            	Type:vo.type});
		}
	}
}